var yfmbgl_app = function() {
	var path = Constants.amUrlPath;
	var ractive;
	var ywy="";
	var csdm="";
	function renderView() {
		ywy = manager.findParamFromUrl("ywy");
		csdm = manager.findParamFromUrl("csdm");
		//参数代码
		csdm=Constants.CSDM.CSDM_JFPB;
		if(ywy==null||ywy==""){ywy="000000";}
		ractive = new Ractive({
			el: ".hp-container",
			template : "#main-template",
			oncomplete : function() {
				var _sc_param = {pageSize : Constants.page.pagesize,currPage : 1,ywy:ywy};
				initTable(_sc_param);
			}
		});

		ractive.on({
			cxbutton : function() {
				var _cx_param = {pageSize : Constants.page.pagesize,currPage : 1};	
				if(ractive.get("jfye")=="0"){alert("当前没有可提现的积分余额！");return}
				function fn_dialog(){
					//兑换积分数
					var dhfs = $.trim(dis.Win.document.getElementById("dhfs").value);
					//兑换的现金
					var hdxj = $.trim(dis.Win.document.getElementById("dhfs").getAttribute("data-hdxj"));
					
					if(dhfs==""||dhfs==null||hdxj==null||hdxj==""){alert("请输入兑换分数！");return}
					var msg = {jsjf:dhfs, jsje:hdxj, ywy:ywy};
					
					$(".libuttonokstyle").attr("disabled", true);
					$.ajax({
						url : Constants.csUrlPath + "yhzhjs/insertJsxx",
						type : "POST",
						dataType : "json",
						contentType : "application/json",
						data:JSON.stringify(msg),
						success : function(obj) {
							$(".libuttonokstyle").removeAttr("disabled");
						    if(obj.result){
						    	wdDialogClosed("dialog");
								var objs3 = {txt : "操作成功！",callBackFun : function() {location.reload(true)}};
								success(objs3);
						    }else{
						    	manager.errorMsg(obj);
						    }
						}
					});	
					
				}
				
				var objs={
					url:"zhhjs-tx.html?csz="+ractive.get("csz")+"&ywy="+ywy+"&jfye="+ractive.get("jfye"),
					title:"提现",
					width:540,
					height:295,
					successCallBackFun:fn_dialog
				};
				var dis = top.dialog(objs);

			}
		});
	}

	/**
	 * 获取参数
	 */
	function review() {
		var _param = {};
		if (typeof ractive != "undefined") {
			var param = ractive.get("jsxc");
		}
		return _param;
	}
	/**
	 * 获取列表数据
	 */
	function initTable(param) {
		
		ractive.set("jfye","0");
		ractive.set("csz","0");
		//获取积分余额
			$.ajax({
				url : Constants.csUrlPath + "yhzhjs/getYhsyjf",
				type : "GET",
				dataType : "json",
				contentType : "application/json",
				data:{},
				success : function(obj) {
					if(obj!=null&&obj!=""){
						ractive.set("jfye",obj);
					}
				}
			});
		
		$.ajax({
			url : Constants.csUrlPath + "common/getXtcsszByCsdm?ywy="+ywy+"&csdm="+csdm,
			type : "GET",
			dataType : "json",
			contentType : "application/json",
			data:{},
			success : function(obj) {
				if(obj!=null&&obj.csz!=""){ 
					ractive.set("csz",obj.csz);
				}
			}
		});
		
		
		
		var _title_txsj = "提现时间";
		var _title_jydh = "交易单号";
		var _title_dhjfe = "兑换积分额";
		var _title_txje = "提现金额";
		var _title_clzt = "处理状态";
		
		
	
		var _table_title = [_title_txsj,_title_jydh,_title_dhjfe, _title_txje, _title_clzt];
		var _col_model = [
				{
					name : 'sqsj',
					width : 40,
					innerhtml:function(opts){
						if(opts.sqsj){
							return moment(opts.sqsj).format("YYYY-MM-DD HH:mm:ss");
						}
							return null;
							
					}
				},
				{
					name : 'zfbddbh',
					width : 40
				},
				{
					name : 'jsjf',
					width : 40
				},
				{
					name : 'jsje',
					width : 40
				},
				{
					name : 'jszt',
					width : 80,
					innerhtml:function(opts){
						if(opts.jszt==Constants.JSZT.JSZT_WJS){
							//未结算
							return "<label style='color:#ff8000;'>处理中</label>";
						}else{
							return "<label>已完成</label>";
						}
						
					}
				}];
		jQuery("#wd-table").wdGrid({
			url:Constants.csUrlPath+'yhzhjs/getJsxxpagination',
			colNames : _table_title,
			colModel : _col_model,
			dataType : "GET",
			submitType : "noForm",
			postData : param,
			pager : "#wd-pager",
			rowList: Constants.page.rowList,
	        pagesize: Constants.page.pagesize
		});
	}
	

	
	
	return {
		init : function() {
			renderView();
		}
	};
}();
$(document).ready(yfmbgl_app.init);